using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using System.Collections;
using HyperVSnapin.Object;

namespace HyperVSnapin.Command.Powerstate
{
    [Cmdlet("Suspend", "VM", SupportsShouldProcess = true)]
    public class SuspendVMCommand : Cmdlet
    {
        #region Parameters
        [Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, HelpMessage = "Help Text")]
        [ValidateNotNullOrEmpty]
        public VirtualMachine[] VM
        {
            get;
            set;
        }

        //[Parameter]
        //public SwitchParameter Force
        //{
        //    get;
        //    set;
        //}
        #endregion

        protected override void ProcessRecord()
        {
            try
            {
                foreach (VirtualMachine vm in VM)
                {
                    try
                    {
                        vm.RequestStateChange(HyperVSnapin.Object.Enums.EnabledStateEnum.Paused);
                    }
                    catch (Exception ex)
                    {
                        WriteError(new ErrorRecord(ex, "PauseVMCommand" + ex, ErrorCategory.NotSpecified, null));
                    }
                }
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "PauseVMCommand" + ex, ErrorCategory.NotSpecified, null));
            }
        }
    }
}
